const mongoose = require("mongoose")

// 创建分类schema

const cateSchema = new mongoose.Schema({
    cateName:{
        type:String,
        required:true
    },
    cateIcon:{
        type:String,
        default:""
    },
    cateDesc:{
        type:String,
        default:""
    },
    pid:{
        type:String,
        default:"0" // 0代表顶层分类
    }
})

// 创建cateModel
const cateModel = mongoose.model("qf_cates",cateSchema);

// 获取所有的分类
const getAllCates = (params={})=>cateModel.find({}).limit(parseInt(params.pageSize)).skip((params.curr-1)*params.pageSize).sort({"_id":-1});
const _getAllCates = (params={})=>cateModel.find(params);
const addCate = (params={})=>cateModel.insertMany(params);
// 获取分类总条数
const getCount = ()=>cateModel.count();
const getCateById = (_id)=>cateModel.findById(_id);
// 编辑 更新分类
const updateCate = ({ query ,content }) => cateModel.update(query,content);
// var { a,b } = obj;
// 删除分类
const delCate = (params={})=> cateModel.remove(params);
module.exports = {
    getAllCates,
    addCate,
    getCount,
    _getAllCates,
    getCateById,
    updateCate,
    delCate
}